using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Collections;
using System.Drawing;
using System.Workflow.ComponentModel;
using System.Workflow.ComponentModel.Design;
using System.Workflow.ComponentModel.Compiler;
using System.Workflow.ComponentModel.Serialization;
using System.Workflow.Runtime;
using System.Workflow.Activities;
using System.Workflow.Activities.Rules;
using Decav.Gatsb.Mobile;
using Decav.Gatsb.Data;

namespace Decav.Gatsb.Application.CommandWorkflow
{
    /// <summary>
    /// Waits for user input from an SMS message by temporarially suspending
    /// the workflow.
    /// </summary>
	public partial class WaitUserResponseActivity: SequenceActivity
	{
		public WaitUserResponseActivity()
		{
			InitializeComponent();
		}

        /// <summary>
        /// The dependency property that gets or sets the body of the message to send.
        /// </summary>
        public static DependencyProperty MessageBodyProperty = DependencyProperty.Register(
            "MessageBody", typeof(string), typeof(WaitUserResponseActivity));

        /// <summary>
        /// Gets or sets the body of the message to send.
        /// </summary>
        [ValidationOption(ValidationOption.Required)]
        public string MessageBody
        {
            get { return (string)GetValue(MessageBodyProperty); }
            set { SetValue(MessageBodyProperty, value); }
        }

        /// <summary>
        /// The dependency property that gets or sets the response sent from the user.
        /// </summary>
        public static DependencyProperty UserResponseProperty = DependencyProperty.Register(
            "UserResponse", typeof(MobileMessage), typeof(WaitUserResponseActivity));

        /// <summary>
        /// Gets or sets the response sent from the user.
        /// </summary>
        [CategoryAttribute("Output")]
        public MobileMessage UserResponse
        {
            get { return (MobileMessage)GetValue(UserResponseProperty); }
            set { SetValue(UserResponseProperty, value); }
        }

        /// <summary>
        /// The dependency property that gets or sets the mailing address for this session/workflow.
        /// </summary>
        public static DependencyProperty WorkflowMailAddressProperty = DependencyProperty.Register(
            "WorkflowMailAddress", typeof(string), typeof(WaitUserResponseActivity));

        /// <summary>
        /// Gets or sets the mailing address for this session/workflow.
        /// </summary>
        [DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Hidden)]
        [BrowsableAttribute(false)]
        [CategoryAttribute("Output")]
        public string WorkflowMailAddress
        {
            get { return (string)GetValue(WorkflowMailAddressProperty); }
            set { SetValue(WorkflowMailAddressProperty, value); }
        }
        

        private void createSessionToken_ExecuteCode(object sender, EventArgs e)
        {
            using (IGatsbDataAdapter adapt = GatsbApplication.Current.GetDataAdapter())
                WorkflowMailAddress = adapt.SaveWorkflowId(this.WorkflowInstanceId);
        }

        public static DependencyProperty GetResponseEventArgsProperty = DependencyProperty.Register("GetResponseEventArgs", typeof(Decav.Gatsb.Application.WorkflowMessageResponseReceivedEventArgs), typeof(Decav.Gatsb.Application.CommandWorkflow.WaitUserResponseActivity));

        /// <summary>
        /// Gets the event arguments of the response.
        /// </summary>
        [DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Hidden)]
        [BrowsableAttribute(false)]
        [CategoryAttribute("Output")]
        public WorkflowMessageResponseReceivedEventArgs GetResponseEventArgs
        {
            get
            {
                return ((Decav.Gatsb.Application.WorkflowMessageResponseReceivedEventArgs)(base.GetValue(Decav.Gatsb.Application.CommandWorkflow.WaitUserResponseActivity.GetResponseEventArgsProperty)));
            }
            set
            {
                base.SetValue(Decav.Gatsb.Application.CommandWorkflow.WaitUserResponseActivity.GetResponseEventArgsProperty, value);
            }
        }

        private void setResponseValue_ExecuteCode(object sender, EventArgs e)
        {
            UserResponse = GetResponseEventArgs.Message;
        }
        
	}
}
